let input = [1, 2]
let [first, second] = input // 1 2
console.log(first, second)
let [first11, second11] = [second, first]
console.log(first11, second11) // 2 1
// 用于函数参数
let input2 = [1, 2];
function f([first, second]: number[]) {
  console.log('first', first) // 1
  console.log('second', second) // 2 
}
f(input2)


let [first1, ...rest] = [1, 2, 3, 4]
console.log(first1, rest) //1 (3) [2, 3, 4]

let [first3] = [1, 2, 4]
console.log('first3', first3) // 1

let [, , third, , fifvth] = [1, 2, 3, 4, 5]
console.log('third', third) // 3
console.log('fifvth', fifvth)// 5

// 对象解构
let o = {
  a: 'foo',
  b: 2
}
let {a, b} = o
 console.log('a', a) // foo
 console.log('b', b) // 2
let {a1, b1} = {a1: 2, b1: 101}
console.log('a1', a1) // 2
console.log('b1', b1) // 101

// ...语法创建剩余变量
let ob = {
  a2: 'lee',
  b: 43,
  c: 'monkey'
}
let {a2, ...pass} = ob
console.log('a2', a2) // lee
console.log('pass', pass) // b: 43, c: "monkey"

// 属性 重命名
let {a2: a222, b: ceb} = ob
console.log('a222', a222) // lee
console.log('ceb', ceb) // 43

// 在对象解构中指定类型
let Obj2 = {
  a3: 1,
  b3: 2
}
let {a3, b3} : {a3: number, b3: number} = Obj2
console.log('a3', a3) // 1
console.log('b3', b3) // 2

// 默认值
function keepWholeObject (whoObject: {a: string, b?: number}) {
  let {a, b = 100} = whoObject
  console.log(a)
  console.log(b)
}

//函数声明
type C = {a: string, b: string}
function f1({a, b}: C) : void {
  console.log('void')
}


